package io;

import java.io.*;
import java.util.Scanner;

/**
 * 简易记事本
 * 程序启动后，用户输入的每一行字符串写入到note.txt中，用户输入exit退出
 */
public class Test3 {
    public static void main(String[] args) throws IOException {
        /*FileOutputStream fos = new FileOutputStream("./note.txt");
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner input = new Scanner(System.in);
        System.out.println("开始输入：");
        boolean flag = input.hasNext();
        while(flag){
            String str = input.nextLine();
            if("exit".equalsIgnoreCase(str)){
                System.out.println("已退出");
                break;

            }
            pw.println(str);

            System.out.println("本行写入完毕");
        }
        System.out.println("结束...");
        pw.close();*/

        FileOutputStream fos = new FileOutputStream("./test.txt");
        OutputStreamWriter osr = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osr);
        PrintWriter pw = new PrintWriter(bw,true);
        Scanner input = new Scanner(System.in);
        System.out.println("请输入,以exit结束");
        while(true){
            String str = input.nextLine();
            if("exit".equalsIgnoreCase(str)){
                System.out.println("退出...");
                break;
            }
            pw.println(str);

        }
        pw.close();

    }

}
